home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 189 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.6 KB

  1. Path: mujibur.inmind.com!usenet
  2. From: mfinney@inmind.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Hungarian notation
  5. Date: 3 Jan 1996 02:36:14 GMT
  6. Organization: In Mind, Inc.
  7. Message-ID: <4ccq2u$3e3@mujibur.inmind.com>
  8. References: <cmanDK7x13.5KM@netcom.com> <verec-2712952049000001@ppp30.micronet.fr> <30E39BC0.3BAE@zeta.org.au> <verec-2912950003390001@ppp05.micronet.fr> <30E55183.52FF@zeta.org.au> <4c44dh$771@mujibur.inmind.com> <4c477m$ou4@macaw.cyberport.com>
  9. Reply-To: mfinney@inmind.com
  10. NNTP-Posting-Host: finneyman.inmind.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4c477m$ou4@macaw.cyberport.com>, tkennedy@cyberport.com (Warren Young) writes:
  14. >mfinney@inmind.com wrote:
  15.  
  16. >Sure the semantics change.  Try passing the latter to printf() and see
  17. >how broken the program gets.  Or strlen(), or strtou()...  Granted,
  18. >you're likely to be changing the string manipulation functions at the
  19. >same time, but this is one place where HN becomes useful: helping you
  20. >find the places where you missed a function call that needs changing.
  21.  
  22. In all of the cases, except printf(), the function prototypes (everyone
  23. uses those, right?) will catch any type change which is incorrect.  And
  24. printf() is kinda obsolete.  If you are dealing with wide character types
  25. you are almost certainly not going to be using printf().  But, even if you
  26. were, a global grep for printf / "insufficientStorage" would catch all of
  27. those combinations.  So Hungarian notation doesn't buy you much here.
  28.  
  29. And surely, there are no functions requiring ellipses in the prototype
  30. in anything written recently?  Certainly not in any code my company
  31. writes nor in any code I  have written in the past two decades.  Type
  32. safefty is available in the language.  Those who don't use it get what
  33. they deserve.
  34.  
  35. >>The use of upper case names to distinguish #define names is one
  36. >>of the worst pseudo-standards that have been fostered upon the
  37. >>programming community.  Right up there with Hungarian notation.
  38. >
  39. >It's very useful with macros, because it tells the reader, "Hey!  The
  40. >arguments to this macro aren't type-safe and there may be
  41. >side-effects!"  With C++, though, I have a solution that both of us
  42. >might find acceptable: dump #defines for consts and inline functions.
  43.  
  44. Only sometimes.  I personally use const data elements and inline
  45. functions whereever possible.  But they simply do not replace
  46. all uses of #define.  And if you have very many global constants
  47. the use of const data elements can add a LOT of space to the
  48. compiled program.  Not always acceptable.  With #defines and
  49. constant folding in the compiler/linker that is less of a problem.
  50.  
  51. And macro functions are still useful -- although much less frequently
  52. than in the past.  I have used them to "map" a common function to
  53. different operating systems.  Here, even the inline template function
  54. doesn't work well.  Further, the code is reduced since the alternate
  55. operating system code goes away at compile time.  An example of
  56. this is the _beginthread() function under OS/2 and NT.  They are
  57. "almost" the same.
  58.  
  59. Another example was the use of printf() in some
  60. C code.  It turns out that the Microsoft compiler didn't support printf()
  61. in the library for some types of programs, but you could call a system
  62. wprintf() to do the same thing (with restricted types, but that was
  63. acceptable for the project).  The use of #define allowed a direct map
  64. for the appropriate operating system.  I don't recommend the use of
  65. C, printf() or any Microsoft operating system but those were the
  66. restrictions I had to live with for that project (but that same project
  67. had to be portable to other systems).
  68.  
  69.  
  70. Michael Lee Finney
  71.  
  72.